﻿<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:converters="clr-namespace:ReporterControlLibrary.Converters" 
	mc:Ignorable="d"
	x:Class="ReporterControlLibrary.EvaluatePathToolbox"
	x:Name="uc"
	d:DesignWidth="260" d:DesignHeight="480" MinWidth="260">
    <UserControl.Resources>

        <converters:IntToBoolConverter x:Key="AddButonEnabledConverter" SourceValue="0" MatchValue="False" MisMatchValue="True" />
        
        <DataTemplate x:Key="ModelPropertyDataTemplate">
            <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,0,0,0" >
                <CheckBox Content="{Binding Name}" Checked="PropertyCheckBoxChecked"  Unchecked="PropertyCheckBoxUnchecked"/>
                <Button Content="+" Click="ApplyPropertyClick" VerticalAlignment="Center" HorizontalContentAlignment="Center" HorizontalAlignment="Right" VerticalContentAlignment="Center" Width="19" Height="19" Padding="1,-2,1,1" FontSize="16" ToolTip="Apply method" d:LayoutOverrides="GridBox" Grid.Column="2" />
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="ModelReferenceDataTemplate">
            <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,0,0,0" >
                <CheckBox Content="{Binding Name}" Checked="ReferenceCheckBoxChecked"  Unchecked="ReferenceCheckBoxUnchecked"/>
                <Button Content="+" Click="ApplyReferenceClick" VerticalAlignment="Center" HorizontalContentAlignment="Center" HorizontalAlignment="Right" VerticalContentAlignment="Center" Width="19" Height="19" Padding="1,-2,1,1" FontSize="16" ToolTip="Apply method" d:LayoutOverrides="GridBox" Grid.Column="2" />
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="ModelUsedByDataTemplate">
            <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,0,0,0" >
                <CheckBox Content="{Binding Name}" Checked="UsedByCheckBoxChecked"  Unchecked="UsedByCheckBoxUnchecked"/>
                <Button Content="+" Click="ApplyUsedByClick" VerticalAlignment="Center" HorizontalContentAlignment="Center" HorizontalAlignment="Right" VerticalContentAlignment="Center" Width="19" Height="19" Padding="1,-2,1,1" FontSize="16" ToolTip="Apply method" d:LayoutOverrides="GridBox" Grid.Column="2" />
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="ModelTypeDataTemplate">
            <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,0,0,0" >
                <CheckBox Content="{Binding Name}" Checked="FilterTypeCheckBoxChecked"  Unchecked="FilterTypeCheckBoxUnchecked"/>
                <Button Content="+" Click="ApplyFilterTypeClick" VerticalAlignment="Center" HorizontalContentAlignment="Center" HorizontalAlignment="Right" VerticalContentAlignment="Center" Width="19" Height="19" Padding="1,-2,1,1" FontSize="16" ToolTip="Apply method" d:LayoutOverrides="GridBox" Grid.Column="2" />
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="ModelMethodDataTemplate">
            <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,0,0,0" >
                <TextBlock Text="{Binding Name}" VerticalAlignment="Center" HorizontalAlignment="Left" Style="{DynamicResource FormLabelStyle}"/>
                <Button Content="+" Click="ApplyMethodClick" VerticalAlignment="Center" HorizontalContentAlignment="Center" HorizontalAlignment="Right" VerticalContentAlignment="Center" Width="19" Height="19" Padding="1,-2,1,1" FontSize="16" ToolTip="Apply method" d:LayoutOverrides="GridBox" Grid.Column="2" />
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="StoredExpressionDataTemplate">
            <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,0,0,0" >
                <TextBlock Text="{Binding ShortDescription}" VerticalAlignment="Center" HorizontalAlignment="Left" Style="{DynamicResource FormLabelStyle}"/>
                <Button Content="+" Click="ApplyStoredExpressionClick" VerticalAlignment="Center" HorizontalContentAlignment="Center" HorizontalAlignment="Right" VerticalContentAlignment="Center" Width="19" Height="19" Padding="1,-2,1,1" FontSize="16" ToolTip="Apply method" d:LayoutOverrides="GridBox" Grid.Column="2" />
            </Grid>
        </DataTemplate>        

        <!-- Methods ListBoxItem Container Style -->
        <Style  x:Key="MethodListBoxItem" TargetType="{x:Type ListBoxItem}">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="Margin" Value="0,1"/>
            <Setter Property="Background" Value="{DynamicResource ControlDarkOpaqueBrushKey}"/>
            <Setter Property="Template" Value="{DynamicResource MethodListBoxItemTemplate}"/>
            <Setter Property="Padding" Value="2"/>
        </Style>
        <ControlTemplate x:Key="MethodListBoxItemTemplate" TargetType="{x:Type ListBoxItem}">
            <Border x:Name="Bd" MouseMove="MethodListBoxItemMouseMove" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True" CornerRadius="5">
                <ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <!--<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>-->
                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                </Trigger>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="IsSelected" Value="True"/>
                        <Condition Property="Selector.IsSelectionActive" Value="False"/>
                    </MultiTrigger.Conditions>
                    <!--<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>-->
                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                </MultiTrigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
        
        <!-- Toolbox ListBoxItem Container Style -->
        <Style  x:Key="ToolboxListBoxItem" TargetType="{x:Type ListBoxItem}">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="Margin" Value="0,1"/>
            <Setter Property="Background" Value="{DynamicResource ControlDarkOpaqueBrushKey}"/>
            <Setter Property="Template" Value="{DynamicResource ToolboxListBoxItemTemplate}"/>
            <Setter Property="Padding" Value="2"/>
        </Style>
        <ControlTemplate x:Key="ToolboxListBoxItemTemplate" TargetType="{x:Type ListBoxItem}">
            <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True" CornerRadius="5">
                <ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <!--<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>-->
                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                </Trigger>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="IsSelected" Value="True"/>
                        <Condition Property="Selector.IsSelectionActive" Value="False"/>
                    </MultiTrigger.Conditions>
                    <!--<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>-->
                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                </MultiTrigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

        <!-- Methods ListBoxItem Container Style -->
        <Style  x:Key="StoredExpressionListBoxItem" TargetType="{x:Type ListBoxItem}">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="Margin" Value="0,1"/>
            <Setter Property="Background" Value="{DynamicResource ControlDarkOpaqueBrushKey}"/>
            <Setter Property="Template" Value="{DynamicResource StoredExpressionListBoxItemTemplate}"/>
            <Setter Property="Padding" Value="2"/>
        </Style>
        <ControlTemplate x:Key="StoredExpressionListBoxItemTemplate" TargetType="{x:Type ListBoxItem}">
            <Border x:Name="Bd" MouseMove="StoredExpressionListBoxItemMouseMove" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True" CornerRadius="5">
                <ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <!--<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>-->
                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                </Trigger>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="IsSelected" Value="True"/>
                        <Condition Property="Selector.IsSelectionActive" Value="False"/>
                    </MultiTrigger.Conditions>
                    <!--<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>-->
                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                </MultiTrigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>


    </UserControl.Resources>

    <Border x:Name="LayoutRoot" Style="{DynamicResource PanelOuterStyle}" Background="{DynamicResource ControlDarkOpaqueBrushKey}" DataContext="{Binding Path=ModelStructure}">
        <ScrollViewer Grid.Column="2" Margin="0,5" Grid.Row="1" VerticalScrollBarVisibility="Auto" Style="{DynamicResource ToolboxScrollViewerStyle}" VerticalAlignment="Top">
            <StackPanel Orientation="Vertical" d:LayoutOverrides="Height">
                <!--Properties Panel-->
                <Border Style="{DynamicResource PanelInnerStyle}">
                    <Grid Margin="3">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="27"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Properties" VerticalAlignment="Center" Style="{DynamicResource FormLabelValueStyle}" Margin="3,0,0,0" />
                        <Button x:Name="ApplyPropertiesBtn" IsEnabled="{Binding ElementName=uc, Path=SelectedProperties.Count, Converter={StaticResource AddButonEnabledConverter}}" Click="ApplyPropertiesClick" Content="+" VerticalAlignment="Center" HorizontalContentAlignment="Center" HorizontalAlignment="Right" VerticalContentAlignment="Center" Width="19" Height="19" Padding="1,-2,1,1" FontSize="16" ToolTip="Apply filter types" d:LayoutOverrides="GridBox" />
                        <ListBox x:Name="PropertiesList" ItemContainerStyle="{DynamicResource ToolboxListBoxItem}" HorizontalContentAlignment="Stretch" ItemTemplate="{DynamicResource ModelPropertyDataTemplate}" ItemsSource="{Binding ModelProperties, Mode=OneWay}" Margin="5,0" Grid.Row="1"/>
                    </Grid>
                </Border>
                <!--References Panel-->
                <Border Style="{DynamicResource PanelInnerStyle}">
                    <Grid Margin="3">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="27"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="References" VerticalAlignment="Center" Style="{DynamicResource FormLabelValueStyle}" Margin="3,0,0,0" />
                        <Button x:Name="ApplyReferencesBtn" IsEnabled="{Binding ElementName=uc, Path=SelectedReferences.Count, Converter={StaticResource AddButonEnabledConverter}}" Click="ApplyReferencesClick" Content="+" VerticalAlignment="Center" HorizontalContentAlignment="Center" HorizontalAlignment="Right" VerticalContentAlignment="Center" Width="19" Height="19" Padding="1,-2,1,1" FontSize="16" ToolTip="Apply filter types" d:LayoutOverrides="GridBox" />
                        <ListBox x:Name="ReferencesList" ItemContainerStyle="{DynamicResource ToolboxListBoxItem}" HorizontalContentAlignment="Stretch" ItemTemplate="{DynamicResource ModelReferenceDataTemplate}" ItemsSource="{Binding ModelReferences, Mode=OneWay}" Margin="5,0" Grid.Row="1"/>
                    </Grid>
                </Border>
                <!--UsedBys Panel-->
                <Border Style="{DynamicResource PanelInnerStyle}">
                    <Grid Margin="3">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="27"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Used By" VerticalAlignment="Center" Style="{DynamicResource FormLabelValueStyle}" Margin="3,0,0,0" />
                        <Button x:Name="ApplyUsedBysBtn" IsEnabled="{Binding ElementName=uc, Path=SelectedUseBys.Count, Converter={StaticResource AddButonEnabledConverter}}" Click="ApplyUsedBysClick" Content="+" VerticalAlignment="Center" HorizontalContentAlignment="Center" HorizontalAlignment="Right" VerticalContentAlignment="Center" Width="19" Height="19" Padding="1,-2,1,1" FontSize="16" ToolTip="Apply filter types" d:LayoutOverrides="GridBox" />
                        <ListBox x:Name="UsedBysList" ItemContainerStyle="{DynamicResource ToolboxListBoxItem}" HorizontalContentAlignment="Stretch" ItemTemplate="{DynamicResource ModelUsedByDataTemplate}" ItemsSource="{Binding ModelUsedBys, Mode=OneWay}" Margin="5,0" Grid.Row="1"/>
                    </Grid>
                </Border>
                <!--Filter Types Panel-->
                <Border Style="{DynamicResource PanelInnerStyle}">
                    <Grid Margin="3">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="27"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Filter Types" VerticalAlignment="Center" Style="{DynamicResource FormLabelValueStyle}" Margin="3,0,0,0" />
                        <Button x:Name="ApplyFilterTypesBtn" IsEnabled="{Binding ElementName=uc, Path=SelectedFilterTypes.Count, Converter={StaticResource AddButonEnabledConverter}}" Click="ApplyFilterTypesClick" Content="+" VerticalAlignment="Center" HorizontalContentAlignment="Center" HorizontalAlignment="Right" VerticalContentAlignment="Center" Width="19" Height="19" Padding="1,-2,1,1" FontSize="16" ToolTip="Apply filter types" d:LayoutOverrides="GridBox" />
                        <ListBox x:Name="FilterTypesList" ItemContainerStyle="{DynamicResource ToolboxListBoxItem}" HorizontalContentAlignment="Stretch" ItemTemplate="{DynamicResource ModelTypeDataTemplate}" ItemsSource="{Binding ModelTypes, Mode=OneWay}" Margin="5,0" Grid.Row="1"/>
                    </Grid>
                </Border>
                <!--Methods Panel-->
                <Border Style="{DynamicResource PanelInnerStyle}">
                    <Grid Margin="3">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="27"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Methods" VerticalAlignment="Center" Style="{DynamicResource FormLabelValueStyle}" Margin="3,0,0,0"/>
                        <ListBox x:Name="MethodsList" ItemContainerStyle="{DynamicResource MethodListBoxItem}" HorizontalContentAlignment="Stretch" ItemTemplate="{DynamicResource ModelMethodDataTemplate}" HorizontalAlignment="Stretch" Grid.Row="1" Margin="0,5" VerticalAlignment="Top" ItemsSource="{Binding ModelMethods}"/>
                        <TextBlock x:Name="MethodDescription" TextWrapping="Wrap" Text="{Binding Description}" DataContext="{Binding SelectedItem, ElementName=MethodsList}" VerticalAlignment="Center" Style="{DynamicResource FormLabelStyle}" Grid.Row="3" d:LayoutOverrides="GridBox" Margin="3,0,3,3" Foreground="{DynamicResource LightBrush}"/>
                    </Grid>
                </Border>
                <!--Methods Panel-->
                <Border Style="{DynamicResource PanelInnerStyle}">
                    <Grid Margin="3">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="27"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Stored Expression" VerticalAlignment="Center" Style="{DynamicResource FormLabelValueStyle}" Margin="3,0,0,0"/>
                        <Button x:Name="RefreshStoredExpressionsBtn" Click="RefreshStoredExpression" Content="Refresh" VerticalAlignment="Center" HorizontalContentAlignment="Center" HorizontalAlignment="Right" VerticalContentAlignment="Center" Height="19" Padding="3,2" FontSize="11" ToolTip="Refresh list of stored expressions" d:LayoutOverrides="GridBox" />
                        <ListBox x:Name="StoredExpressionList" ItemContainerStyle="{DynamicResource StoredExpressionListBoxItem}" HorizontalContentAlignment="Stretch" ItemTemplate="{DynamicResource StoredExpressionDataTemplate}" HorizontalAlignment="Stretch" Grid.Row="1" Margin="0,5" VerticalAlignment="Top" ItemsSource="{Binding ModelStoredExpressions}"/>
                        <TextBlock x:Name="StoredExpressionDescription" TextWrapping="Wrap" Text="{Binding Description}" DataContext="{Binding SelectedItem, ElementName=StoredExpressionList}" VerticalAlignment="Center" Style="{DynamicResource FormLabelStyle}" Grid.Row="3" d:LayoutOverrides="GridBox" Margin="3,0,3,3" Foreground="{DynamicResource LightBrush}"/>
                    </Grid>
                </Border>                
            </StackPanel>
        </ScrollViewer>
    </Border>
</UserControl>